feeTrialDataTree = {};
if (!Array.prototype.find) {
    Object.defineProperty(Array.prototype, 'find', {
        value: function(predicate) {
        // 1. Let O be ? ToObject(this value).
        if (this == null) {
            throw new TypeError('"this" is null or not defined');
        }

        var o = Object(this);

        // 2. Let len be ? ToLength(? Get(O, "length")).
        var len = o.length >>> 0;

        // 3. If IsCallable(predicate) is false, throw a TypeError exception.
        if (typeof predicate !== 'function') {
            throw new TypeError('predicate must be a function');
        }

        // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
        var thisArg = arguments[1];

        // 5. Let k be 0.
        var k = 0;

        // 6. Repeat, while k < len
        while (k < len) {
            // a. Let Pk be ! ToString(k).
            // b. Let kValue be ? Get(O, Pk).
            // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
            // d. If testResult is true, return kValue.
            var kValue = o[k];
            if (predicate.call(thisArg, kValue, k, o)) {
            return kValue;
            }
            // e. Increase k by 1.
            k++;
        }

        // 7. Return undefined.
        return undefined;
        }
    });
}
function sortNum(a,b) {
    return a - b;
};
var feeTrialService = {
    removeType:function(arr,val){
        arr.sort(sortNum).forEach(function(item,index){
            if(item === val && index > -1){
                arr.splice(index,1)
            }
            return arr
        });
    },
    chooseTypeNo:function(no){
        var self = this;
        if(no == 0){
            if(this.refs.haiyun.checked){
                self.state.productType.push(1)
            }else{
                self.removeType(self.state.productType,1)
            }
        }
        if(no == 1){
            if(this.refs.kongyun.checked){
                self.state.productType.push(6)
            }else{
                self.removeType(self.state.productType,6)
            }
        }
        if(no == 2){
            if(this.refs.sudi.checked){
                self.state.productType.push(11)
            }else{
                self.removeType(self.state.productType,11)
            }
        }
    },
    floatConfigure:function(arg1,arg2){
        var r1,r2,m;
        try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
        try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
        m = Math.pow(10,Math.max(r1,r2))
        return (arg1 * m + arg2 * m) / m
    },
    clearNextAddress: function (currentEle) {
        var self = this;
        var nextEle = currentEle.next;
        if (nextEle == null) {
            return;
        }
        nextEle.clearData();
        nextEle.id = null;
        return self.clearNextAddress(nextEle);
    },
    clearValueByKey: function (obj, key) {
        var menu = [
            "countryCode","countryName",
            "provinceCode", "provinceName",
            "cityCode", "cityName",
            "districtCode", "districtName",
            "streetCode", "streetName"
        ];
        if (menu.indexOf(key) == -1) {
            return;
        }
        for (var s = menu.indexOf(key), len = menu.length; s < len; s++) {
            obj[menu[s]] = "";
        }
        return obj;
    },
    createSelectBox: function (domId, data, config, cback) {
        var parentChildMenu = {
            "fromProvince": "fromCountry",
            "fromCity": "fromProvince",
            "fromDistrict": "fromCity",
            "fromStreet": "fromDistrict",
            "fromState": "fromCountry",
            "endProvince": "endCountry",
            "endCity": "endProvince",
            "endDistrict": "endCity",
            "endStreet": "endDistrict",
            "endState": "endCountry"
        };
        var self = this;
        var selectEle = selectFactory({
            data: {data : data},
            id: domId,
            isSearch: config ? config.isSearch : false,
            isUsePinyin: true,
            isSaveInputVal: true,
            closeLocalSearch: true,
            showTextField: (config&&config.showTextField)  ? config.showTextField : "name",
            maxHeight: 160,
            defaultCount: 1000,
            pagination: config.pagination ? config.pagination : false,
            defaultText: "请选择",
            searchPlaceHoder:config?config.searchPlaceHoder : "请输入搜索条件",
            onSearchValueChange: config.onSearchValueChange,
            attrTextModel: config.attrTextModel
        });
        selectEle.setData(data);
        if (Select.sharePool[parentChildMenu[domId]]) {
            Select.sharePool[parentChildMenu[domId]].next = selectEle;
        }
        if(cback){
            cback();
        }
    },
    getCountryList: function (id, q, type, currentPage) {
        var self = this;
        Api.get('address.countryList', {
            urlParams: {
                q: q || "",
                customerId: cookie.get("userId") || "",
                type: type,
                pageIndex: currentPage || 1,
                pageSize: 10
            }
        }, function (res) {
            self.createSelectBox(id, {data: res}, {
                isSearch: true,
                showTextField:"showName",
                searchPlaceHoder:"请输入国家名称或二字码",
                pagination:true,
                defaultCount:11,
                onSearchValueChange: function (attachEvent, q, currentPage) {
                    Api.get('address.countryList', {
                        urlParams: {
                            q: q || "",
                            customerId: cookie.get("userId") || "",
                            type: type,
                            pageIndex: currentPage || 1,
                            pageSize: 10
                        }
                    }, function(result){
                        if(result.errorCode === 0){
                            result.data.map(function(item){
                                item.showName = item.name + "(" + item.figureCode + ")";
                            })
                            attachEvent.setData(result);
                        }
                    });
                },
                attrTextModel: function (name, data) {
                    var cargoUnit;
                    var data = this.allData;
                    if (!name) {
                        cargoUnit = {};
                    } else {
                        cargoUnit = data.data.find(function (item) {
                            return item.showName == name;
                        })
                    }
                    var stateData = self.state;
                    var isFromAddress = id == "fromCountry";
                    if (isFromAddress) {
                        stateData.fromAddress = self.clearValueByKey(stateData.fromAddress, "countryCode");
                        stateData.fromAddress.countryName = cargoUnit.name||"";
                        stateData.fromAddress.countryCode = cargoUnit.figureCode||"";
                        stateData.fromAddress.isCnAddress = cargoUnit.figureCode == "CN";
                        Select.sharePool['fromState'].clearData();
                    } else {
                        stateData.endAddress = self.clearValueByKey(stateData.endAddress, "countryCode");
                        stateData.endAddress.countryName = cargoUnit.name;
                        stateData.endAddress.countryCode = cargoUnit.figureCode||"";
                        stateData.endAddress.isCnAddress = cargoUnit.figureCode == "CN";
                        Select.sharePool['endState'].clearData();
                    }
                    if(id == "fromCountry") {
                        self.clearNextAddress(Select.sharePool["fromProvince"]);
                        Select.sharePool["fromProvince"].clearData();
                    } else if(id == "endCountry") {
                        self.clearNextAddress(Select.sharePool["endProvince"]);
                        Select.sharePool["endProvince"].clearData();
                    }
                    self.clearNextAddress(Select.sharePool[id]);
                    self.setState(stateData);
                    self.formCheck();

                }
            });
        })
    },
    initAreaList : function(domId, q, nameStr, codeStr, delKey, nextLevel){
        var areaMenu = {
            "from": {
                "fromState": "countryCode",
                "fromProvince": "countryCode",
                "fromCity": "provinceCode",
                "fromDistrict": "cityCode",
                "fromStreet": "districtCode"
            },
            "end": {
                "endState": "countryCode",
                "endProvince": "countryCode",
                "endCity": "provinceCode",
                "endDistrict": "cityCode",
                "endStreet": "districtCode"
            }
        };
        var self = this;
        var stateData = self.state;
        var isFromAddress = domId.indexOf("from") > -1;
        var areaTempMenu = isFromAddress ? areaMenu['from'] : areaMenu['end'];
        if (delKey) {
            var tempObj = {
                isSearch: true,
                pagination:true,
                closeLocalSearch:true,
                searchPlaceHoder:"请输入城市名称",
                onSearchValueChange: function (attachEvent, q, currentPage) {

                    var isFromAddress = domId.indexOf("from") > -1;
                    var areaTempMenu = isFromAddress ? areaMenu['from'] : areaMenu['end'];
                    var pId = isFromAddress ? stateData.fromAddress[areaTempMenu[domId]] : stateData.endAddress[areaTempMenu[domId]];
                    var cCode = isFromAddress ? stateData.fromAddress.countryCode : stateData.endAddress.countryCode;
                    if(!(pId && cCode)) {
                        return;
                    }
                    Api.get('address.searchList', {
                        urlParams: {
                            q: q || "",
                            pageIndex: currentPage || 1,
                            pageSize: "10",
                            parentId: pId,
                            countryCode: cCode
                        }
                    }, function (res) {
                        if(res.errorCode === 0){
                            attachEvent.setData(res);
                        }
                    })
                    //self.getAreaList(domId, q, nameStr, codeStr);
                }
            }
        } else {
            var tempObj = {
                isSearch: false
            }
        }
        self.createSelectBox(domId, {data:[]}, $.extend(tempObj, {
                isHasListBoxEle:delKey,
                attrTextModel: function (name, data) {
                    var areaUnit;
                    var data = this.allData;
                    if (!name) {
                        areaUnit = {};
                    } else {
                        areaUnit = data.data.find(function (item) {
                            return item.name == name;
                        })
                    }
                    var stateData = self.state;
                    if (isFromAddress) {
                        stateData.fromAddress = self.clearValueByKey(stateData.fromAddress, delKey || codeStr);
                        stateData.fromAddress[nameStr] = areaUnit.name;
                        stateData.fromAddress[codeStr] = areaUnit.id;
                    } else {
                        stateData.endAddress = self.clearValueByKey(stateData.endAddress, delKey || codeStr);
                        stateData.endAddress[nameStr] = areaUnit.name;
                        stateData.endAddress[codeStr] = areaUnit.id;
                    }
                    self.clearNextAddress(Select.sharePool[domId]);
                    self.formCheck();
                    self.setState(stateData);

                    /*打开下一个子节点*/
                    if(nextLevel){
                        self.getAreaList(nextLevel);
                    }

                }
            }))
    },
    getAreaList: function (domId, q) {
        var areaMenu = {
            "from": {
                "fromState": "countryCode",
                "fromProvince": "countryCode",
                "fromCity": "provinceCode",
                "fromDistrict": "cityCode",
                "fromStreet": "districtCode"
            },
            "end": {
                "endState": "countryCode",
                "endProvince": "countryCode",
                "endCity": "provinceCode",
                "endDistrict": "cityCode",
                "endStreet": "districtCode"
            }
        };
        var self = this;
        var stateData = self.state;
        var isFromAddress = domId.indexOf("from") > -1;
        var areaTempMenu = isFromAddress ? areaMenu['from'] : areaMenu['end'];
        var pId = isFromAddress ? stateData.fromAddress[areaTempMenu[domId]] : stateData.endAddress[areaTempMenu[domId]];
        var cCode = isFromAddress ? stateData.fromAddress.countryCode : stateData.endAddress.countryCode;
        if(!(pId && cCode)) {
            return;
        }else{
            Api.get('address.searchList', {
                urlParams: {
                    q: q || "",
                    pageIndex: "1",
                    pageSize: "1000",
                    parentId: pId,
                    countryCode: cCode
                }
            }, function (res) {
                Select.sharePool[domId].setData(res);
                if(domId != 'fromState' && domId != 'toState'){
                    Select.sharePool[domId].open();
                }

            })
        }
    },
    //范围
    getRange: function () {
        var self = this;
        if (feeTrialDataTree && feeTrialDataTree.rangeList) {
            self.createSelectBox('range', feeTrialDataTree.rangeList,{
            });
        } else {
            var res=[{id:0,name:"类型",code:"type"},{id:1,name:"产品",code:"product"}];
            var search = selectFactory({
                data: {data:res},
                id: "range",
                defaultText:'',
                isSearch: false,
                attrTextModel: function (name, data) {
                    var data = this.allData;
                    if (!name) {
                        var rangeList = {};
                    } else {
                        var rangeList = data.data.find(function (item) {
                            return item.name == name;
                        })
                    }
                    var stateData = self.state;
                    stateData.range = rangeList.name ||"";
                    stateData.rangeCode = rangeList.code ||"";
                    if(stateData.rangeCode === "type"){
                        self.state.typeDisplay = "block";
                        self.state.productDisplay = "none";
                        self.state.productName = "";
                        self.refs.kongyun.checked = false;
                        self.refs.haiyun.checked = false;
                        self.refs.sudi.checked = false;
                        self.state.productType = [];
                        self.state.productCode = []
                    }
                    if(stateData.rangeCode === "product"){
                        self.state.typeDisplay = "none";
                        self.state.productDisplay = "block";
                        self.state.productName = "";
                        self.refs.kongyun.checked = false;
                        self.refs.haiyun.checked = false;
                        self.refs.sudi.checked = false;
                        self.state.productType = [];
                        self.state.productCode = []
                    }
                    self.setState(stateData);
                }
            });
        }
    },
    //产品
    productList : function(q, currentPage, fn){
        if(!currentPage) {
            currentPage = 1;
        }
        Api.get("feeTrial.getProduct",{"urlParams" : {q : q, pageIndex: currentPage, pageSize:10}},fn);
    },
    getProduct: function () {
        var self = this , resDatas;
        Api.get('feeTrial.getProduct',{"urlParams" :{pageSize:1000}}, function (resData) {
            resDatas = resData.data
        });
        if (feeTrialDataTree && feeTrialDataTree.productList) {
            self.createSelectBox('product', feeTrialDataTree.productList,{});
        } else {
            Api.get('feeTrial.getProduct', function (res) {
                feeTrialDataTree.productList = res;
                var search = selectFactory({
                    data: res,
                    id: "product",
                    offset: -300,
                    isSearch: true,
                    isUsePinyin: true,
                    pagination: true,
                    multipleSign: ",",
                    closeLocalSearch: true,
                    searchPlaceHoder:"请输入名称",
                    defaultText:'请选择',
                    onSearchValueChange: function (attachEvent, q, currentPage) {
                        self.productList(q, currentPage, function (res) {
                            search.setData(res);
                        });
                    },
                    attrTextModel: function (name, data) {
                        var stateData = self.state,productList;
                        stateData.productName = name;
                        stateData.productCode= [];
                        if (!name) {
                            productList = {};
                        } else {
                            var names = name.split("，");
                            names.forEach(function(value){
                                productList = resDatas.find(function (item){
                                    return item.name == value;
                                });
                                stateData.productCode.push(productList.uid);
                            });
                        }
                        self.setState(stateData);
                    }
                });
            })
        }
    },
    //货物类型
    getCargoTypeList: function () {
        var self = this;
        if (feeTrialDataTree && feeTrialDataTree.cargoTypeList) {
           self.createSelectBox('cargoType', feeTrialDataTree.cargoTypeList,{

           });
        } else {
            Api.get('feeTrial.getCargoType', function (res) {
                feeTrialDataTree.cargoTypeList = res;
                self.createSelectBox('cargoType', res, {
                    isSearch:false,
                    onSearchValueChange: function (attachEvent, da, q) {

                    },
                    attrTextModel: function (name, data) {
                        var data = this.allData;
                        if (!name) {
                            var cargoTypeList = {};
                        } else {
                            var cargoTypeList = data.data.find(function (item) {
                                return item.name == name;
                            })
                        }
                        var stateData = self.state;
                        stateData.cargoTypeName  = cargoTypeList.name||"";
                        stateData.cargoTypeCode  = cargoTypeList.code||"";
                        self.setState(stateData);
                        self.formCheck();
                    }
                },function(){
                    Select.sharePool.cargoType.attrTextModel("普通大包",Select.sharePool.cargoType.data);
                    Select.sharePool.cargoType.inputElement.val("普通大包");
                });
            })
        }
    },
    //计量单位
    getCargoUnitList: function () {
        var self = this;
        if (feeTrialDataTree && feeTrialDataTree.cargoUnitList) {
           self.createSelectBox('cargoUnit', feeTrialDataTree.cargoUnitList,{
               showTextField:"code",
           });
        } else {
            Api.get('feeTrial.getCargoUnitList', function (res) {
                if(res.errorCode == 0){
                    feeTrialDataTree.cargoUnitList = res;
                    self.createSelectBox('cargoUnit', res, {
                        isSearch:false,
                        showTextField:"code",
                        attrTextModel: function (name, data) {
                            var data = this.allData;
                            if (!name) {
                                var cargoUnitList = {};
                            } else {
                                var cargoUnitList = data.data.find(function (item) {
                                    return item.code == name;
                                })
                            }
                            var stateData = self.state;
                            cargoUnitList = cargoUnitList ? cargoUnitList : {};
                            stateData.cargoUnitName  = cargoUnitList.name||"";
                            stateData.cargoUnitCode  = cargoUnitList.code||"";
                            self.setState(stateData);
                            self.formCheck();
                        }
                    },function(){
                        Select.sharePool.cargoUnit.attrTextModel("kg",Select.sharePool.cargoUnit.data);
                        Select.sharePool.cargoUnit.inputElement.val("kg");
                    });
                }
            })
        }
    },
    //货币单位
    getCurrencyUnitList: function (q) {
        var self = this;
        if($("#currencyUnit").attr("disabled") == "disabled"){
            return;
        }
        if (feeTrialDataTree && feeTrialDataTree.currencyUnitList) {
            if(q){
                var selectBox = feeTrialDataTree.currencyUnitList.data.filter(function(item){
                    if(item.code){
                        return  item.showName.indexOf(q) > -1 ||  item.code.indexOf(q.toUpperCase()) > -1
                    }else{
                        return item.showName.indexOf(q) > -1
                    }
                })
            }else{
                var selectBox = feeTrialDataTree.currencyUnitList.data;
            }
            self.createSelectBox('currencyUnit',{data:selectBox},{
                searchPlaceHoder:"请输入币种名称或三字码",
                attrTextModel: function (name, data) {
                    var data = this.allData;
                    if (!name) {
                        var currencyUnitList = {};
                    } else {
                        var currencyUnitList = data.data.find(function (item) {
                            return item.showName == name;
                        })
                    }
                    var stateData = self.state;

                    stateData.currencyUnitName  = currencyUnitList.name||"";
                    stateData.currencyUnitCode  = currencyUnitList.code||"";
                    self.setState(stateData);
                    self.formCheck();
                }
            });
        } else {
            Api.get('feeTrial.getCurrencyUnitList',function (res) {
                if(res.errorCode == 0){
                    res.data.map(function(item){
                        item.showName = item.name + "(" + item.code + ")";
                    });
                    feeTrialDataTree.currencyUnitList = res;
                    self.createSelectBox('currencyUnit', res, {
                        isSearch:true,
                        showTextField:"showName",
                        searchPlaceHoder:"请输入币种名称或三字码",
                        onSearchValueChange: function (attachEvent, da, q) {
                            da = $.trim(da);
                            self.getCurrencyUnitList(da);
                        },
                        attrTextModel: function (name, data) {
                            var data = this.allData;
                            if (!name) {
                                var currencyUnitList = {};
                            } else {
                                var currencyUnitList = data.data.find(function (item) {
                                    return item.showName == name||item.name == name;
                                })
                            }
                            var stateData = self.state;

                            currencyUnitList = currencyUnitList ? currencyUnitList : {};
                            stateData.currencyUnitName  = currencyUnitList.name||"";
                            stateData.currencyUnitCode  = currencyUnitList.code||"";
                            self.setState(stateData);
                            self.formCheck();
                            Select.sharePool.currencyUnit.inputElement.val(currencyUnitList.name);
                        }
                    },function(){
                        Api.get("feeTrial.customerCurrency",{},function(res){
                            if(res.errorCode == 0){
                                Select.sharePool.currencyUnit.attrTextModel(res.data.currencyName,Select.sharePool.currencyUnit.data);
                                Select.sharePool.currencyUnit.inputElement.val(res.data.currencyName);
                                $("#currencyUnit").attr("disabled","disabled");
                                self.setState({'currencyUnitCode':res.data.currencyCode});
                            }else{
                                Select.sharePool.currencyUnit.attrTextModel("人民币(CNY)",Select.sharePool.currencyUnit.data);
                                Select.sharePool.currencyUnit.inputElement.val("人民币");
                                self.setState({'currencyUnitCode':'CNY'});
                            }
                        })
                    });
                }
            })
        }
    },
    lwhChange: function (index, key, event) {
        var self = this;
        var stateData = this.state;
        stateData.lwhList[index][key] = event.target.value;
        self.formCheck();
        self.showOrHideTip();
    },
    isCouldAdd: function () {
        var self = this;
        var flag = true;
        var stateData = self.state;
        var lwhList = stateData.lwhList;
        lwhList.map(function (item) {
            if (!item['weight']) {
                flag = false;
                return;
            } else {
                //三者同时存在或者同时不存在
                if ((item['width'] && item['length'] && item['height']) || (!item['width'] && !item['length'] && !item['height'])) {

                } else {
                    flag = false;
                    return;
                }
            }
        });
        return flag;
    },
    addItem: function () {
        var self = this;
        var stateData = self.state;
        if (!self.isCouldAdd()) {
            stateData.lwhErrorTips = "请完善重量数据"
        } else {
            stateData.lwhErrorTips = ""
            var stateData = self.state;
            stateData.lwhList.push({
                length: "",
                width: "",
                height: "",
                weight: ""
            });
        }
        self.setState(stateData);
    },
    delItem: function (index) {
        var self = this;
        var stateData = self.state;
        stateData.lwhList.splice(index, 1);
        self.setState(stateData);
        self.showOrHideTip();
    },
    configureMoney: function (index, th, event) {
        var self = this;
        var stateData = self.state;
        stateData.gridDataList[index]['service'][th].checked = !stateData.gridDataList[index]['service'][th].checked;

        var optionServiceSelected = [];
        var optionServiceList = stateData.grid[index]['optionalServices'];
        optionServiceList.map(function (item) {
            if (item.checked) {
                optionServiceSelected.push(item);
            }
        });
        var noneOptServiceList = stateData.grid[index]['noneOptionalServices'];
         var feeList = [];
        var total = stateData.grid[index]['totalAmount'];
        noneOptServiceList.map(function (noneOpt) {
            feeList.push({
                name: noneOpt.feeTypeName,
                value: noneOpt.amount
            })
        });
        optionServiceSelected.map(function (opt) {
            total = self.floatConfigure(total,opt.amount);
            feeList.push({
                name: opt.feeTypeName,
                value: opt.amount
            })
        });
        feeList.unshift({
            name: "总价:",
            value: total + "(" + stateData.grid[index]['currencyCode'] + ")"
        });
        stateData.gridDataList[index].feePrice = feeList;
        self.setState(stateData);
    },
    formCheck: function () {
        var flag = false;
        var self = this;
        var dataState = self.state;
        if(dataState.submitted != true){
            return;
        }
        var currencyCargo = [{
            "id": "currencyUnit",
            "key": "currencyUnitCode"
        }, {
            "id": "cargoUnit",
            "key": "cargoUnitCode"
        }, {
            "id": "cargoType",
            "key": "cargoTypeCode"
        }];
        currencyCargo.map(function (item) {
            if (!dataState[item['key']]) {
                $("#" + item['id']).addClass("error");
                flag = true;
            } else {
                $("#" + item['id']).removeClass("error");
            }
        });
        if(dataState.fromAddress.isCnAddress){
            var fromList = [{
                id:"fromCountry",
                key:"countryCode"
            }]
        }else{
            var fromList = [{
                id:"fromCountry",
                key:"countryCode"
            }]
        }
        if(dataState.endAddress.isCnAddress){
            var endList = [{
                id:"endCountry",
                key:"countryCode"
            }]
        }else{
            var endList = [{
                id:"endCountry",
                key:"countryCode"
            }]
        }
        fromList.map(function(item){
            if(!dataState['fromAddress'][item['key']]){
                $("#" + item['id']).addClass("error");
                flag = true;
            }else{
                $("#" + item['id']).removeClass("error");
            }
        })
        endList.map(function(item){
            if(!dataState['endAddress'][item['key']]){
                $("#" + item['id']).addClass("error");
                flag = true;
            }else{
                $("#" + item['id']).removeClass("error");
            }
        });

        var len = dataState.lwhList.length;
        for(var s = 0;s < len;s++){
            if(!dataState['lwhList'][s]['weight']){
                $("#weight"+ s).addClass("error");
                flag = true;
            }else{
                $("#weight"+ s).removeClass("error");
            }
        }

        return flag;
    },
    showOrHideTip:function(){
        var self = this;
        var stateData = self.state;
        if (!self.isCouldAdd()) {
            stateData.lwhErrorTips = "请完善重量数据"
        } else {
            stateData.lwhErrorTips = ""
        }
        self.setState(stateData);
    },
    search: function () {
        var self = this;
        var stateData = self.state;
        stateData.submitted = true;
        self.setState(stateData);
        if(self.formCheck()){
            return;
        }
        var productType = stateData.productType.sort(sortNum);
        var data = {
            "cargoTypeCode": stateData.cargoTypeCode,
            "currencyCode": stateData.currencyUnitCode,
            "customerId": cookie.get("userId"),
            //"customerId": "", //cookie.get("userId"),
            "fromArea": stateData.fromAddress.districtCode,
            "fromCity": stateData.fromAddress.cityCode,
            "fromCountry": stateData.fromAddress.countryCode,
            "fromPostcode": "",
            "fromProvince": stateData.fromAddress.provinceCode,
            "fromStreet": stateData.fromAddress.streetCode,
            "packages": stateData.lwhList,
            "productUid": "",
            "toArea": stateData.endAddress.districtCode,
            "toCity": stateData.endAddress.cityCode,
            "toCountry": stateData.endAddress.countryCode,
            "toPostcode": "",
            "toProvince": stateData.endAddress.provinceCode,
            "toStreet": stateData.endAddress.streetCode,
            "weightUnitCode": stateData.cargoUnitCode,
            "groupType": productType,
            "mulitProductUid": stateData.productCode
        };
        stateData.scrollTrue = true;
        Api.post('feeTrial.search', {
            urlParams: data
        }, function (res) {
            if(res.errorCode === 0){
                var data = [];
                res.data.map(function (item) {
                    var feeList = [{
                        name: "总价:",
                        value: item['totalAmount'] + "(" + item['currencyCode'] + ")"
                    }];
                    item.noneOptionalServices.map(function (noneOpt) {
                        feeList.push({
                            name: noneOpt.feeTypeName,
                            value: noneOpt.amount
                        })
                    });
                    data.push({
                        groupName: item.groupName,
                        productName: item.productName,
                        service: item.optionalServices,
                        feeWeight: item.feeWeight + "(" + item.feeWeightUnitCode + ")",
                        feePrice: feeList,
                        aging: item.productEstimatedTime ? item.productEstimatedTime + "(" + item.productEstimatedUnit + ")" : "",
                        feeAction: "我要下单"
                    })
                });
                stateData.gridDataList = data;
                stateData.grid = res.data;
            }else{
                stateData.gridDataList = [];
                stateData.grid=[];
            }
            stateData.showGrid = true;
            self.setState(stateData);
        })
    },
    jumpTo: function(index){
        var self = this;
        var stateData = self.state;
        var optServiceIds = "";
        var optServiceUids = "";
        var totalWeight = 0.0;
        var productUid = stateData.grid[index].productUid;
        var productId = stateData.grid[index].productId;
        stateData.lwhList.map(function(item){
            totalWeight = parseFloat(totalWeight) +  parseFloat(item.weight);
        });
        stateData.gridDataList[index].service.map(function(item){
            if(item.checked){
                optServiceIds += item.serviceId + ",";
                optServiceUids += item.serviceTypCode + ",";
            }
        });
        if(optServiceIds[optServiceIds.length - 1] == ","){
            optServiceIds = optServiceIds.substring(0,optServiceIds.length - 1)
        }
        if(optServiceUids[optServiceUids.length - 1] == ","){
            optServiceUids = optServiceUids.substring(0,optServiceUids.length - 1)
        }
        var data = {
            uid:stateData.grid[index].productUid,
            pid:stateData.grid[index].productId,
            serviceId:optServiceIds,
            serviceUid:optServiceUids,
            cargoType:stateData.cargoTypeCode,
            cargoTypeName:stateData.cargoTypeName,
            wlwh:stateData.lwhList,
            cusWeight:totalWeight,
            cusWeightUnit:stateData.cargoUnitCode,
            cusWeightUnitName:stateData.cargoUnitName,
            currencyUnitCode:stateData.currencyUnitCode,
            currencyUnitName:stateData.currencyUnitName,
            fromAddress:{
                countryName:stateData.fromAddress.countryName,
                countryCode:stateData.fromAddress.countryCode,
                provinceName:stateData.fromAddress.provinceName,
                provinceId:stateData.fromAddress.provinceCode,
                cityName:stateData.fromAddress.cityName,
                cityId:stateData.fromAddress.cityCode,
                districtName:stateData.fromAddress.districtName,
                districtId:stateData.fromAddress.districtCode,
                streetName:stateData.fromAddress.streetName,
                streetId:stateData.fromAddress.streetCode
            },
            endAddress:{
                countryName:stateData.endAddress.countryName,
                countryCode:stateData.endAddress.countryCode,
                provinceName:stateData.endAddress.provinceName,
                provinceId:stateData.endAddress.provinceCode,
                cityName:stateData.endAddress.cityName,
                cityId:stateData.endAddress.cityCode,
                districtName:stateData.endAddress.districtName,
                districtId:stateData.endAddress.districtCode,
                streetName:stateData.endAddress.streetName,
                streetId:stateData.endAddress.streetCode
            }
        };
        localStorage.setItem("feeTrialData",JSON.stringify(data));
        location.href = "./orders?pageName=feeTrial"+'&productId='+productId +'&productUid='+productUid+'&serviceids='+ optServiceUids;
    }
};
module.exports = feeTrialService;
